/**
 * Class TargetInitModule.
 *
 * @author Maxime Ollagnier
 */
TargetInitModule.inherits(Module);
function TargetInitModule() {

    this.nethashInput = new InputTextAreaModule({
        id: 'nethashInput',
        resizeable: 'both'
    });

}

TargetInitModule.prototype.fillJQ = function(jQ) {
    var that = this;

    var form = $('<div class="well"></div>');
    jQ.append(form);

    var columnLeft = $('<div class="span1"></div>');
    columnLeft.append($('<div class="btn">Process</div>').click(function() {
        that.processData();
    }));
    var columnRight = $('<div class="span11"></div>');
    columnRight.append(this.nethashInput.buildJQ());
    form.append($('<div class="row-fluid">').append(columnLeft).append(columnRight));
};

TargetInitModule.prototype.loadData = function(callback) {
    Util.getFunction(callback)();
};

TargetInitModule.prototype.processData = function() {
    var hashs = [];
    $.each(this.nethashInput.value.split('\n'), function(i, hash) {
        var hashArray = hash.split(',');
        var target = {
            blockNb : parseInt(hashArray[0]),
            difficulty : parseFloat(hashArray[4])
        }
        hashs.push(target);
    });
    console.debug(hashs);
    //TargetDB.getInstance().save(hashs);
};